package com.m2bshop.shop.controller;

import com.m2bshop.shop.dao.SysparamDao;
import com.m2bshop.shop.pageHelper.paging;
import com.m2bshop.shop.pojo.Sysparam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SysparamController {

    @Autowired
    private SysparamDao sysparamDao;

    @Autowired
    private paging paging;

    @RequestMapping("/countSysparam")
    public int count(){
        return sysparamDao.count();
    }

    @RequestMapping("/findallSysparam/{pagenum}/{pagesize}")     //查询所有系统参数
    public List<Sysparam> findall(@PathVariable  int pagenum, @PathVariable int pagesize){
        paging.pagehelper(pagenum, pagesize);

        return sysparamDao.findall();
    }

    @RequestMapping("/findbyidSysparam/{id}")       //根据ID查询系统参数
    public Sysparam findbyid(@PathVariable int id){
        return sysparamDao.findbyid(id);
    }

    @RequestMapping("/insertoneSysparam")   //新增系统参数
    public int insertone(String ppkey, String paravalue, String paradescrip){
        Sysparam sysparam = new Sysparam();
        sysparam.setPpkey(ppkey);
        sysparam.setParavalue(paravalue);
        sysparam.setParadescrip(paradescrip);
        return  sysparamDao.insertone(sysparam);
    }

    @RequestMapping("/deleteoneSysparam/{id}")      //按id删除
    public int deleteone(@PathVariable int id){
        return sysparamDao.deleteone(id);
    }

    @RequestMapping("/updateoneSysparam")        //按id修改
    public int updateone(Sysparam sysparam){
        return sysparamDao.updateone(sysparam);
    }
}
